package org.tp;

import java_cup.runtime.*;
import java.io.*;

%%
%class TpLexer
%line
%column
%cupsym TpSymbol
%cup

%{
private Symbol symbol (int type) {
    return new Symbol (type, yyline, yycolumn);
}

private Symbol symbol (int type, Object value) {
    return new Symbol (type, yyline, yycolumn, value);
}
%}

Identifier	= [a-zA-Z][a-zA-Z0-9_]*
Char= \'[a-zA-Z]\'
LineTerminator	= \r|\n|\r\n
WhiteSpace	= {LineTerminator} | [ \t\f]
Integer		= [0-9]+
Reel = -?[0-9]+"."[0-9]*
String		= \"[^\"]*\"

%%

/* -------------------------------------------------
	Separateurs Operateurs
   ------------------------------------------------- */

"("		{/*System.out.print(yytext());*/ return symbol(TpSymbol.LPAR); }
")"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.RPAR); }
"{"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.LBRACE); }
"}"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.RBRACE); }
"["		{/*System.out.print(yytext());*/  return symbol(TpSymbol.LBRACKET); }
"]"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.RBRACKET); }
"&&"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.AND); }
"||"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.OR); }
"<"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.LT); }
">"		{/*System.out.print(yytext());*/  return symbol(TpSymbol.GT); }
"<="	{/*System.out.print(yytext());*/  return symbol(TpSymbol.LE); }
">="	{/*System.out.print(yytext());*/  return symbol(TpSymbol.GE); }
"!"	    {/*System.out.print(yytext());*/  return symbol(TpSymbol.NO); }
"!="	{/*System.out.print(yytext());*/  return symbol(TpSymbol.DIFF); }
"="	{/*System.out.print(yytext()+"\n");*/  return symbol(TpSymbol.EQ); }
"+"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.PLUS); }
"++" {/*System.out.print("INCR"+yytext());*/  return symbol(TpSymbol.INCR); }
"-"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.MINUS); }
"--" {System.out.print("DECR"+yytext());  return symbol(TpSymbol.DECR); }
"*"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.MULT); }
"/"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.DIV); }
"%" {/*System.out.print(yytext());*/  return symbol(TpSymbol.MOD); }
";"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.SEMIC); }
"," {/*System.out.print(yytext());*/  return symbol(TpSymbol.VIR); }
":"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.COLON); }
":="	{/*System.out.print(yytext());*/  return symbol(TpSymbol.AFF); }
"."	{/*System.out.print(yytext());*/  return symbol(TpSymbol.POINT); }
"if"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.IF); }
"null"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.NULL); }
"else"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.ELSE); }
"while"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.WHILE); }
"int"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.INT); }
"float" {/*System.out.print(yytext());*/  return symbol(TpSymbol.FLOAT); }
"char"	{/*System.out.print(yytext());*/  return symbol(TpSymbol.CHAR); }
"string" {/*System.out.print(yytext());*/  return symbol(TpSymbol.STRING); }
"list"	{/*System.out.print(yytext()+"\n");*/  return symbol(TpSymbol.LIST); }
"map"	{/*System.out.print(yytext()+"\n");*/  return symbol(TpSymbol.MAP); }
"class"	{/*System.out.print(yytext()+"\n");*/  return symbol(TpSymbol.CLASS); }
"of"	{/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.OF); }
"bool"	{/*System.out.print(yytext()+\"n");*/  return symbol(TpSymbol.BOOLEAN); }
"struct" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.STRUCT);}
"function" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.FUNCTION);}
"enum"		{/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.ENUM);}
"repeat"	{/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.REPEAT);}
"in"	{/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.IN);}
"for" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.FOR);}
"case" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.CASE);}
"procedure" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.PROC);}
"operator" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.OP);}
"return"	{/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.RET);}
"set" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.SET);}
 "print" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.PRINT);}
 "read" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.READ);}
 "break" {/*System.out.print(yytext()+"\n");*/ return symbol(TpSymbol.BREAK);}
/* -------------------------------------------------
	Variables, Entiers
   ------------------------------------------------- */
"true"|"false"  {/*System.out.print(yytext());*/ return symbol(TpSymbol.BOOL, yytext());}

{Char} {/*System.out.print(yytext());*/
					 return symbol(TpSymbol.CHAREXP, yytext());}
					 
{Identifier}	{/*System.out.print(yytext()+"\n");*/
					 return symbol(TpSymbol.IDENTIFIER, yytext());}
{Integer}	{/*System.out.print(yytext()+"\n"); */
				return symbol(TpSymbol.INTEGER, yytext());}
{String}	{/*System.out.print(yytext());*/  
				return symbol(TpSymbol.STRINGEXP, yytext().substring(1, yytext().length()-1)); }
{Reel}		{/*System.out.print(yytext());*/ return symbol(TpSymbol.REAL, yytext());}
/* -------------------------------------------------
	Commentaires - Caracteres non pris en compte
   ------------------------------------------------- */
"/*"( [^"*/"])*"*/"  {}
"//" [^\n\r]* [\n|\r|\r\n]     {}
{WhiteSpace}                   { /*System.out.print(yytext());*/  /* ignore */ }

/* -------------------------------------------------
	Autres signes
   ------------------------------------------------- */
.	{ /* ignore */ }
